<script>
/*
 * @Author: Your name
 * @Date:   2020-07-30 09:00:48
 * @Last Modified by:   Your name
 * @Last Modified time: 2020-08-04 23:20:26
 */
</script>
<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="~assets/img/1.jpg" alt="" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="loginout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          :collapse="isCollapse"
          :collapse-transition="false"
          unique-opened
          default-active
          router
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menuList"
            :key="item.id"
          >
            <!-- 一级菜单 -->
            <template slot="title">
              <i :class=menusIcon[item.id] style="font-size:22px; margin-right: 5px"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/' + itemChil.path"  v-for="itemChil in item.children" :key="itemChil.id">
              <i class="el-icon-menu"></i>
              <span>{{ itemChil.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { request2 } from 'network/request.js'
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: false,
      menuList: [],
      menusIcon: {
        '125': 'iconfont icon-yonghu2',
        '103': 'iconfont icon-shangpinku',
        '101': 'iconfont icon-quanxian',
        '102': 'iconfont icon-dingdan',
        '145': 'iconfont icon-shuju'
      }
    }
  },
  methods: {
    loginout() {
      window.localStorage.clear()
      this.$router.push('/login')
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    async getMenusList() {
      const res = await request2({
        url: '/menus',
        method: 'get'
      })
      // console.log(res)
      this.menuList = res.data
    }
  },
  created() {
    this.getMenusList()
  }
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-container {
}
.el-header {
  background: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  > div {
    color: #ffffff;
    display: flex;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
    span {
      font-size: 20px;
      margin-left: 20px;
    }
  }
}
.el-aside {
  background: #333744;
  .el-menu {
    border-right: none;
  }
  .toggle-button {
    width: 100%;
    text-align: center;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    letter-spacing: 0.1em;
    cursor: pointer;
  }
}
.el-main {
  backgroud: #eaedf1;
}
</style>
